package com.bingxue.edu.management.education.service;

import com.bingxue.edu.management.education.mapper.LessonEvaluationMapper;
import com.bingxue.edu.management.education.model.entity.LessonEvaluation;
import com.bingxue.edu.framework.mybatis.base.BaseService;
import com.bingxue.edu.teacher.model.resp.LessonEvaluationDetailResp;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.bingxue.edu.management.education.model.entity.table.LessonEvaluationTableDef.LESSON_EVALUATION;
import static com.bingxue.edu.management.education.model.entity.table.StudentTableDef.STUDENT;

/**
 * 课次评价务类
 *
 * @author zq
 * @since 2024/08/22
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class LessonEvaluationService extends BaseService<LessonEvaluationMapper, LessonEvaluation> {
    /**
     *  学生评价详情信息
     * @param id 课次id
     * @return
     */
    public List<LessonEvaluationDetailResp> getLessonEvaluationDetail(String id) {
        QueryWrapper queryWrapper = QueryWrapper.create()
                .select(
                        LESSON_EVALUATION.DEFAULT_COLUMNS,
                        STUDENT.ID.as(LessonEvaluationDetailResp::getStudentId),
                        STUDENT.NAME.as(LessonEvaluationDetailResp::getStudentName)
                ).from(LESSON_EVALUATION)
                .leftJoin(STUDENT).on(LESSON_EVALUATION.STUDENT_ID.eq(STUDENT.ID))
                .where(LESSON_EVALUATION.LESSON_ID.eq(id)).and(LESSON_EVALUATION.DISPLAY.eq(1)); // 是否展示;
        return this.getMapper().selectListByQueryAs(queryWrapper,LessonEvaluationDetailResp.class);
    }
}
